package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVo;
import com.tanhua.server.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
public class SettingsController {

    @Autowired
    private SettingsService settingsService;

    /**
     * 查询通用设置
     *   请求地址：
     *      GET /users/settings
     *   返回值：
     *      ResponseEntity<SettingsVo>
     */
    @GetMapping("/settings")
    public ResponseEntity settings() {
        SettingsVo vo = settingsService.settings();
        return ResponseEntity.ok(vo);
    }

    /**
     * 设置陌生人问题：
     *    请求地址：
     *      POST  /users/questions
     *    参数：
     *      Body：content
     *    返回值：
     *      ResponseEntity<null>
     */
    @PostMapping("/questions")
    public ResponseEntity questions(@RequestBody Map map) {
        String content = (String) map.get("content");
        settingsService.saveQuestions(content);
        return ResponseEntity.ok(null);
    }

    /**
     * 设置通知开关
     *  请求地址：
     *   POST  /users/notifications/setting
     * 参数：
     *   Body：likeNotification  pinglunNotification  gonggaoNotification
     * 返回值：
     *   ResponseEntity<null>
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity notifications(@RequestBody Map map) {
        Boolean likeNotification = (Boolean) map.get("likeNotification");
        Boolean pinglunNotification = (Boolean) map.get("pinglunNotification");
        Boolean gonggaoNotification = (Boolean) map.get("gonggaoNotification");
        settingsService.saveNotifications(likeNotification,pinglunNotification,gonggaoNotification);
        return ResponseEntity.ok(null);
    }

    /**
     * 分页查询黑名单
     *  请求地址：GET /users/blacklist?page=1&pagesize=10
     *  参数：
     *     Query：page，pagesize
     *  返回值：
     *     ResponseEntity<PageResult>
     */
    @GetMapping("/blacklist")
    public ResponseEntity blacklist(
           @RequestParam(defaultValue = "1") Integer page,
           @RequestParam(defaultValue = "10")  Integer pagesize) {
        PageResult result = settingsService.blacklist(page,pagesize);
        return ResponseEntity.ok(result);
    }

    /**
     * 移除黑名单
     */
    @DeleteMapping("/blacklist/{blackUserId}")
    public ResponseEntity delBlackList(@PathVariable("blackUserId") Long blackUserId){
        settingsService.delBlackList(blackUserId);
        return ResponseEntity.ok(null);
    }
}
